package ooo.reindeer.commons.utils;

import java.io.Closeable;
import java.net.Socket;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

public class IOUtils {
    public static void release(Object... resources) {
        for (Object resource : resources) {
            if (resource != null) {
                if (resource instanceof Closeable) {
                    try {
                        ((Closeable) resource).close();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                } else if (resource instanceof Connection) {
                    try {
                        ((Connection) resource).close();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                } else if (resource instanceof Statement) {
                    try {
                        ((Statement) resource).close();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                } else if (resource instanceof ResultSet) {
                    try {
                        ((ResultSet) resource).close();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                } else if (resource instanceof Socket) {
                    try {
                        ((Socket) resource).close();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }

        }

    }
}
